﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using MVVM_S.Samples.HelpDesk.ViewModels;

namespace MVVM_S.Samples.HelpDesk.Views
{
    public partial class Ticket : Page
    {
        public Ticket()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            TicketViewModel ticketVM = Resources["TicketVM"] as TicketViewModel;
            if (NavigationContext.QueryString.ContainsKey("TicketID"))
            {
                int ticketID = 0;
                if (int.TryParse(NavigationContext.QueryString["TicketID"], out ticketID))
                {
                    ticketVM.LoadTicket(ticketID);
                    return; // Stop Here
                }
            }

            // Load a New Ticket
            ticketVM.NewTicket();
        }

    }
}
